#include "scalpmap.h"

ScalpMap::ScalpMap(int scalling_, QWidget *parent) :
    QWidget(parent), scalling(scalling_)
{
    scalpmapPixmap = new QPixmap(":/scalpmap.png");
    this->resize(scalpmapPixmap->width()/scalling,scalpmapPixmap->height()/scalling);

    electrodes["P7"].append(291);
    electrodes["P7"].append(316);
    electrodes["P7"].append(0);

    electrodes["P8"].append(534);
    electrodes["P8"].append(316);
    electrodes["P8"].append(0);


    electrodes["FC6"].append(540);
    electrodes["FC6"].append(202);
    electrodes["FC6"].append(0);

    electrodes["FC5"].append(291);
    electrodes["FC5"].append(202);
    electrodes["FC5"].append(0);


    electrodes["T7"].append(240);
    electrodes["T7"].append(246);
    electrodes["T7"].append(0);

    electrodes["T8"].append(590);
    electrodes["T8"].append(246);
    electrodes["T8"].append(0);



    electrodes["O1"].append(373);
    electrodes["O1"].append(343);
    electrodes["O1"].append(0);

    electrodes["O2"].append(450);
    electrodes["O2"].append(343);
    electrodes["O2"].append(0);


    electrodes["F3"].append(348);
    electrodes["F3"].append(171);
    electrodes["F3"].append(0);

    electrodes["F4"].append(484);
    electrodes["F4"].append(171);
    electrodes["F4"].append(0);



    electrodes["F7"].append(269);
    electrodes["F7"].append(154);
    electrodes["F7"].append(0);

    electrodes["F8"].append(562);
    electrodes["F8"].append(154);
    electrodes["F8"].append(0);


    electrodes["AF3"].append(366);
    electrodes["AF3"].append(125);
    electrodes["AF3"].append(0);


    electrodes["AF4"].append(464);
    electrodes["AF4"].append(125);
    electrodes["AF4"].append(0);

}


void ScalpMap::paintEvent(QPaintEvent *event)
{

    QPainter painter(this);

    painter.drawPixmap(0,0,this->width(),this->height(),*scalpmapPixmap);

    foreach (QVector<double> electrode, electrodes)
    {
	painter.setPen(QPen(getElectrodeColor(electrode.at(2))));
	painter.setBrush(QBrush(getElectrodeColor(electrode.at(2))));

	painter.drawRoundedRect(electrode.at(0)/scalling - 10,electrode.at(1)/scalling, 20,20,5,5);

    }

}

void ScalpMap::setCq(QString channel, double cq)
{

    if (electrodes.contains(channel))
	electrodes[channel][2] = cq;

    update();
}

QColor ScalpMap::getElectrodeColor(double value)
{

    if (value < 81)
	return QColor("black");
    if (value < 221)
	return QColor("red");
    if (value < 314)
	return QColor("orange");
    if (value < 407)
	return QColor("yellow");
    if (value >= 407)
	return QColor("lime");

    return QColor("blue");


}
